<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统管理-工作日志模板</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div class="layui-card-body">
                    <div class="panel panel-default operation" hidden>
                        <div class="panel-heading title"></div>
                        <div class="layui-card-body">
                            <form class="layui-form " action="" lay-filter="info" style="margin-top: 10px">
                                <label for="_id"></label>
                                <input id="_id" name="id" hidden/>
                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                                    <legend>模板信息</legend>
                                </fieldset>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">标题</label>
                                    <div class="layui-input-inline">
                                        <input id="surveyTitle" name="surveyTitle" placeholder="请输入模板标题"
                                               autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                                    <legend>模板问题内容</legend>
                                </fieldset>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"></label>

                                    <div class="layui-input-inline">
                                        <div class="layui-btn" onclick="addSurveyContent_1()">增加文本问题</div>
                                    </div>

                                    <div class="layui-input-inline">
                                        <div class="layui-btn" onclick="addSurveyContent_2()">增加多选问题</div>
                                    </div>
                                    <div class="layui-input-inline">
                                        <div class="layui-btn" onclick="addSurveyContent_3()">增加单选问题</div>
                                    </div>

                                </div>
                                <div id="_addSurveyContentDiv">
                                    <div id="_addSurveyContent"></div>
                                </div>
                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                                    <legend>生成模板</legend>
                                </fieldset>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">
                                            生成模板
                                        </button>
                                        <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="panel panel-default operation1" hidden>
                        <div class="panel-heading title"></div>
                        <div class="layui-card-body">
                            <form class="layui-form " action="" lay-filter="info" style="margin-top: 10px">
                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                                    <legend>模板信息</legend>
                                </fieldset>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">标题</label>
                                    <div class="layui-input-inline">
                                        <input id="viewTitle" readonly="true" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                                    <legend>模板问题内容</legend>
                                </fieldset>

                                <div id="viewSurvey"></div>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                                    </div>
                                </div>

                            </form>
                        </div>
                    </div>
                    <div class="table_div">
                        <div class="layui-card-body">
                            <div class="layui-input-inline">
                                <label for="key"></label>
                                <input type="text" id="key" class="layui-input" autocomplete="off"
                                       placeholder="请输入">
                            </div>
                            <div class="layui-input-inline ">
                                <button class="layui-btn" onclick="search()" id="search">查询</button>
                            </div>
                            <table class="layui-table" id="showTable" lay-filter="showTable"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    </div>
</script>
<script type="text/html" id="tool">
    {{#  if(d.state == '0'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="push">发布</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="view">查看</a>
    {{#  }else { }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="view">查看</a>
    {{#  } }}
</script>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var _xh = 0;
    var _surveyArr = [];
    layui.use(['table', 'layer', 'laydate'], function () {
        //日期
        laydate.render({
            elem: '#date'
        });

        //加载table
        tableIns1 = table.render({
            elem: '#showTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            page: true //开启分页
            ,
            url: '/workflow/log/survey/list' //数据接口
            ,
            method: 'POST',
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null
                        : res.data.records
                    //解析数据列表
                }
            },
            cols: [[{
                align: 'center',
                width: 290,
                field: 'id',
                title: '模板编号',
                hide: true
            }, {
                align: 'center',
                width: 530,
                field: 'title',
                title: '模板标题',
                sort: true
            }, {
                field: 'createTime', title: '创建日期', width: 160, align: "center", templet: function (d) {
                    if (!d.createTime) {
                        return '';
                    }
                    return layui.util.toDateString(d.createTime, 'yyyy-MM-dd');
                }
            }, {
                align: 'center',
                width: 260,
                toolbar: "#tool",
                fixed: 'right',
                title: '操作'
            }]],

            toolbar: '#toolbar'
        });

        //表头工具
        table.on('toolbar(showTable)', function (obj) {
            switch (obj.event) {
                case 'batchDeleted':
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    if (data.length == 0) {
                        layer.msg("请选择要批量删除的列");
                    } else {
                        var ids = [];
                        $(data).each(function (index, item) {
                            ids.push(item.id);
                        });
                        tipDialog(ids);
                    }
                    break;
                case 'add':
                    $(".table_div").hide();
                    $(".operation").show();
                    $(".title").html("新增模板");
                    $("#_addSurveyContentDiv").html("<div id='_addSurveyContent'></div>");
                    $(".operation input[name=id]").val("");
                    $(".operation input[name=surveyTitle]").val("");
                    _xh = 0;
                    _surveyArr = new Array();
                    break;
            }
            ;
        });
        //列操作
        table.on('tool(showTable)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    var ids = [];
                    ids.push(data.id);
                    tipDialog(ids);
                    break;
                case 'push':
                    var ids = [];
                    ids.push(data.id);
                    tipPushlog(ids);
                    break;

                case 'edit':

                    $(".table_div").hide();
                    $(".operation").show();
                    $(".title").html("修改模板");
                    $("#_addSurveyContentDiv").html("<div id='_addSurveyContent'></div>");
                    $(".operation input[name=id]").val(data.id);
                    $(".operation input[name=surveyTitle]").val(data.title);

                    // var contentSurveyJson = eval("(" + data.content + ")");
                    var contentSurveyJson = JSON.parse(data.content);
                    _surveyArr = contentSurveyJson;
                    // arr 对象转list
                    for (var ii = 0; ii < _surveyArr.length; ii++) {
                        var optionsArr = _surveyArr[ii].options;
                        var _optionsArr = new Array;

                        for (var _ii in optionsArr) {
                            _optionsArr.push(optionsArr[_ii]);
                        }

                        _surveyArr[ii].options = _optionsArr;
                    }


                    _xh = contentSurveyJson.length;
                    // $("#_addSurveyContent").html("");
                    var tmp = "";
                    for (var i = 0; i < contentSurveyJson.length; i++) {
                        var _optionsType = contentSurveyJson[i].optionsType;
                        var _optionsTitle = contentSurveyJson[i].optionsTitle;
                        var optionsArr = contentSurveyJson[i].options;

                        if (_optionsType == "1") {
                            // 文本
                            tmp += "<div id='wj_" + i + "'>"
                                + "<div class='layui-form-item'>"
                                + "<label class='layui-form-label'>文本问题</label>"
                                + "<div class='layui-input-inline'>"
                                + "<input onkeyup='javascript:insertArry(this, " + i + ");' id='wjnrId_" + i + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input' value='" + _optionsTitle + "'>"
                                + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteOptions(" + i + ")'>删除</a>";

                            if (optionsArr[0] == "date") {
                                tmp += "<div onclick='dateOptions(" + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox layui-form-checked' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>"
                            } else {
                                tmp += "<div onclick='dateOptions(" + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                            }

                            tmp += "<a>日期类型</a>"
                                + "</div>"
                                + "</div>"
                                + "</div>";

                        } else if (_optionsType == "2") {
                            // 多选
                            tmp += "<div id='wj_" + i + "'>"
                                + "<div class='layui-form-item'>"
                                + "<label class='layui-form-label'>多选问题</label>"
                                + "<div class='layui-input-inline'>"
                                + "<input onkeyup='javascript:insertArry(this, " + i + ");' id='wjnrId_" + i + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input' value='" + _optionsTitle + "'>"
                                + "<a style='cursor:pointer' onclick='deleteOptions(" + i + ")'>删除</a>"
                                + "</div>"
                                // + "<label class='layui-form-label'></label>"
                                + "<div class='layui-input-inline'>"
                                + "<div class='layui-btn layui-btn-danger layui-btn-xs' onclick='addWjnrxx(" + i + ")'>增加多选</div>"
                                + "</div>"
                                + "<div class='layui-form-item'>"
                                + "<label id='options_" + i + "' style='line-height: 60px' class='layui-form-label'>选项</label>"

                            // 遍历处理 optionsArr
                            for (var _i in optionsArr) {
                                var _t = optionsArr[_i][0];
                                var _f = optionsArr[_i][1];

                                tmp += "<div class='layui-input-inline' id='optionsDiv_" + i + "_" + _i + "'>"
                                    + "<input onkeyup='javascript:insertArry1(this, " + i + ", " + _i + ");' id='wjnrxxId_" + i + "' name='wjnrxxName' placeholder='请输入选项' autocomplete='off' class='layui-input' value='" + _t + "'>"
                                    + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteoptions(" + _i + "," + i + ")'>删除</a>";
                                if (_f) {
                                    tmp += "<div onclick='inputOptions(" + _i + "," + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox layui-form-checked' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                                } else {
                                    tmp += "<div onclick='inputOptions(" + _i + "," + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                                }
                                tmp += "<a>文本框选项</a>"
                                    + "</div>";
                            }

                            +"</div>"
                            + "</div>"
                            + "</div>";
                            // 	遍历处理 optionsArr

                        } else if (_optionsType == "3") {
                            // 单选
                            tmp += "<div id='wj_" + i + "'>"
                                + "<div class='layui-form-item'>"
                                + "<label class='layui-form-label'>单选问题</label>"
                                + "<div class='layui-input-inline'>"
                                + "<input onkeyup='javascript:insertArry(this, " + i + ");' id='wjnrId_" + i + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input' value='" + _optionsTitle + "'>"
                                + "<a style='cursor:pointer' onclick='deleteOptions(" + i + ")'>删除</a>"
                                + "</div>"
                                // + "<label class='layui-form-label'></label>"
                                + "<div class='layui-input-inline'>"
                                + "<div class='layui-btn layui-btn-danger layui-btn-xs' onclick='addWjnrxx(" + i + ")'>增加单选</div>"
                                + "</div>"
                                + "<div class='layui-form-item'>"
                                + "<label id='options_" + i + "' style='line-height: 60px' class='layui-form-label'>选项</label>"

                            // 遍历处理 optionsArr
                            for (var _i in optionsArr) {
                                var _t = optionsArr[_i][0];
                                var _f = optionsArr[_i][1];

                                tmp += "<div class='layui-input-inline' id='optionsDiv_" + i + "_" + _i + "'>"
                                    + "<input onkeyup='javascript:insertArry1(this, " + i + ", " + _i + ");' id='wjnrxxId_" + i + "' name='wjnrxxName' placeholder='请输入选项' autocomplete='off' class='layui-input' value='" + _t + "'>"
                                    + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteoptions(" + _i + "," + i + ")'>删除</a>";
                                if (_f) {
                                    tmp += "<div onclick='inputOptions(" + _i + "," + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox layui-form-checked' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                                } else {
                                    tmp += "<div onclick='inputOptions(" + _i + "," + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                                }
                                tmp += "<a>文本框选项</a>"
                                    + "</div>";
                            }

                            +"</div>"
                            + "</div>"
                            + "</div>";


                        }
                    }

                    $("#_addSurveyContent").html(tmp);
                    break;

                case 'view':
                    $(".table_div").hide();
                    $(".operation").hide();
                    $(".operation1").show();

                    var contentSurveyJson = eval("(" + data.content + ")");

                    $("#viewTitle").val(data.title);
                    var viewSurveyTmp = "";
                    for (var i = 0; i < contentSurveyJson.length; i++) {
                        var _optionsType = contentSurveyJson[i].optionsType;
                        var _optionsTitle = contentSurveyJson[i].optionsTitle;
                        viewSurveyTmp += "<div class='layui-form-item'>";
                        if (_optionsType == "1") {
                            // 文本
                            viewSurveyTmp += "<label class='layui-form-label'>" + _optionsTitle + "</label>"
                                + "<div class='layui-input-block'>"
                                + "<input type='text' placeholder='请输入' autocomplete='off' class='layui-input'>"
                                + "</div>";
                        } else if (_optionsType == "2") {
                            // 多选
                            viewSurveyTmp += "<label class='layui-form-label'>" + _optionsTitle + "</label>"
                                + "<div class='layui-input-block'>";
                            var _options = contentSurveyJson[i].options;
                            for (var _i in _options) {
                                // for(var _i = 0; _i < _options.length; _i++){
                                var flag = _options[_i][1];
                                viewSurveyTmp += "<input type='checkbox' name=" + _options[_i][0] + " title=" + _options[_i][0] + ">"
                                    + "<div class='layui-unselect layui-form-checkbox'><span>" + _options[_i][0] + "</span>"
                                    + "<i class='layui-icon layui-icon-ok'></i>"

                                viewSurveyTmp += "</div><br>";
                                if (flag) {
                                    viewSurveyTmp += "<input type='text' class='layui-input'>"
                                }
                            }

                            viewSurveyTmp += "</div>";

                        } else if (_optionsType == "3") {
                            // 单选
                            viewSurveyTmp += "<label class='layui-form-label'>" + _optionsTitle + "</label>"
                                + "<div class='layui-input-block'>";
                            var _options = contentSurveyJson[i].options;
                            for (var _i in _options) {

                                var flag = _options[_i][1];
                                viewSurveyTmp += "<input type='radio' name='like[write]' value=" + _options[_i][0] + " title=" + _options[_i][0] + ">"
                                    + "<div class='layui-unselect layui-form-radio'>"
                                    + "<i class='layui-anim layui-icon'>o</i><div>" + _options[_i][0] + "</div>";
                                if (flag) {
                                    viewSurveyTmp += "<input type='text' class='layui-input'>";
                                }
                                viewSurveyTmp += "</div><br>";
                            }
                            viewSurveyTmp += "</div>";
                        }
                        viewSurveyTmp += "</div>";
                    }

                    $("#viewSurvey").html(viewSurveyTmp);
                    break;
            }
        });

        //删除
        var tipDialog = function (ids) {
            layer.open({
                content: "确定要删除么?",
                yes: function (index, layero) {
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                    CoreUtil.sendDelete("/workflow/log/survey/del", ids, function (res) {
                        layer.msg(res.msg, {
                            time: 1000
                        }, function () {
                            search();
                        });
                    });
                }
            });
        };


        var tipPushlog = function (ids) {
            layer.open({
                content: "确定要发布么?",
                yes: function (index, layero) {
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                    CoreUtil.sendDelete("/workflow/log/survey/push", ids, function (res) {
                        layer.msg(res.msg, {
                            time: 1000
                        }, function () {
                            search();
                        });
                    });
                }
            });
        };

        //返回
        $("#btn_cancel").click(function () {
            $(".table_div").show();
            $(".operation").hide();
            return false;
        });

        //监听保存
        form.on('submit(submit)', function (data) {

            var surveyTitle = $("#surveyTitle").val();
            var _id = $("#_id").val();

            if (CoreUtil.isEmpty(surveyTitle)) {
                layer.msg("模板标题未填写，请填写!");
                return false;
            }
            ;

            var _obj = new Array;

            if (_surveyArr.length > 0) {
                for (var i in _surveyArr) {
                    var map = {};
                    var optionsTitle = _surveyArr[i].optionsTitle;

                    if (CoreUtil.isEmpty(optionsTitle)) {
                        layer.msg("存在未填写的模板选项标题，请填写!");
                        return false;
                    }
                    ;

                    var optionsType = _surveyArr[i].optionsType;
                    var _servey = {};
                    map["optionsTitle"] = optionsTitle;
                    map["optionsType"] = optionsType;

                    var optionsArr = _surveyArr[i].options;
                    var _options = {};

                    if (optionsType != "1") {
                        // 处理选择类的
                        if (optionsArr.length > 0) {
                            for (var _i in optionsArr) {
                                if (CoreUtil.isEmpty(optionsArr[_i])) {
                                    layer.msg("存在未填写的模板问题选项，请填写!");
                                    return false;
                                } else {
                                    _options[_i] = optionsArr[_i];
                                }

                            }
                            ;
                        } else {
                            layer.msg("存在未添加的模板问题选项，请添加!");
                            return false;
                        }

                    } else {
                        // 处理文本类的
                        if (optionsArr.length > 0) {
                            for (var _i in optionsArr) {
                                if (CoreUtil.isEmpty(optionsArr[_i])) {

                                } else {
                                    _options[_i] = optionsArr[_i];
                                }

                            }
                            ;
                        }
                    }

                    map["options"] = _options;
                    _obj.push(map);

                }
            } else {
                layer.msg("还是设置模板问题，请添加!");
                return false;
            }

            console.log(JSON.stringify(_obj));

            var mapArr = {
                'id': _id,
                'surveyTitle': surveyTitle,
                'optionsConent': JSON.stringify(_obj),
            };

            CoreUtil.sendPost("/workflow/log/survey/add", mapArr, function (res) {

                if (res.code == 0) {
                    $(".table_div").show();
                    $(".operation").hide();
                    search();
                } else {
                    layer.msg(res.msg);
                    return false;
                }

            });

            return false;
        });
    });

    //执行查询
    function search() {
        //这里以搜索为例
        tableIns1.reload({
            where: { //设定异步数据接口的额外参数，任意设
                title: $("#key").val()
            },
            page: {
                curr: 1
                //重新从第 1 页开始
            }
        });
    };

    // 增加文本框
    function addSurveyContent_1() {

        var surveyOptionsArr = {};
        surveyOptionsArr["options"] = new Array();
        _surveyArr[_xh] = surveyOptionsArr;
        _surveyArr[_xh]['optionsType'] = "1";

        // var xh = _xh;
        var xh = _surveyArr.length - 1;
        var tmp = "";
        tmp += "<div id='wj_" + xh + "'>"
            + "<div class='layui-form-item'>"
            + "<label class='layui-form-label'>文本问题</label>"
            + "<div class='layui-input-inline'>"
            + "<input onkeyup='javascript:insertArry(this, " + xh + ");' id='wjnrId_" + xh + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input'>"
            + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteOptions(" + xh + ")'>删除</a>"
            + "<div onclick='dateOptions(" + xh + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>"
            + "<a>日期类型</a>"
            + "</div>"
            + "</div>"
            + "</div>";

        _xh++;

        $("#_addSurveyContent").after(tmp);

    }

    // 增加多选框
    function addSurveyContent_2() {
        var surveyOptionsArr = {};
        surveyOptionsArr["options"] = new Array();
        _surveyArr[_xh] = surveyOptionsArr;
        _surveyArr[_xh]['optionsType'] = "2";

        // var xh = _xh;
        var xh = _surveyArr.length - 1;
        var tmp = "";
        tmp += "<div id='wj_" + xh + "'>"
            + "<div class='layui-form-item'>"
            + "<label class='layui-form-label'>多选问题</label>"
            + "<div class='layui-input-inline'>"
            + "<input onkeyup='javascript:insertArry(this, " + xh + ");' id='wjnrId_" + xh + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input'>"
            + "<a style='cursor:pointer' onclick='deleteOptions(" + xh + ")'>删除</a>"
            + "</div>"
            // + "<label class='layui-form-label'></label>"
            + "<div class='layui-input-inline'>"
            + "<div class='layui-btn layui-btn-danger layui-btn-xs' onclick='addWjnrxx(" + xh + ")'>增加多选</div>"
            + "</div>"
            + "<div class='layui-form-item'>"
            + "<label id='options_" + xh + "' style='line-height: 60px' class='layui-form-label'>选项</label>"
            + "</div>"
            + "</div>"
            + "</div>";
        _xh++;

        $("#_addSurveyContent").after(tmp);

    }

    // 增加单选框
    function addSurveyContent_3() {
        var surveyOptionsArr = {};
        surveyOptionsArr["options"] = new Array();
        _surveyArr[_xh] = surveyOptionsArr;
        _surveyArr[_xh]['optionsType'] = "3";

        // var xh = _xh;
        var xh = _surveyArr.length - 1;
        var tmp = "";
        tmp += "<div id='wj_" + xh + "'>"
            + "<div class='layui-form-item'>"
            + "<label class='layui-form-label'>单选问题</label>"
            + "<div class='layui-input-inline'>"
            + "<input onkeyup='javascript:insertArry(this, " + xh + ");' id='wjnrId_" + xh + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input'>"
            + "<a style='cursor:pointer' onclick='deleteOptions(" + xh + ")'>删除</a>"
            + "</div>"
            // + "<label class='layui-form-label'></label>"
            + "<div class='layui-input-inline'>"
            + "<div class='layui-btn layui-btn-danger layui-btn-xs' onclick='addWjnrxx(" + xh + ")'>增加单选</div>"
            + "</div>"
            + "<div class='layui-form-item'>"
            + "<label id='options_" + xh + "' style='line-height: 60px' class='layui-form-label'>选项</label>"
            + "</div>"
            + "</div>"
            + "</div>";
        _xh++;

        $("#_addSurveyContent").after(tmp);

    }

    function addWjnrxx(xh) {
        var tmp = "";
        var _surveyOptionsArr = _surveyArr[xh];
        var _wjnrxxArry = {};

        if (_surveyOptionsArr.options.length >= 16) {
            layer.msg("模板内容选择框最多新增16条");
            return false;
        }
        ;

        var _optionsArr = _surveyOptionsArr["options"];
        _optionsArr.push(_wjnrxxArry);

        var _xxxh = _optionsArr.length - 1;
        tmp += "<div class='layui-input-inline' id='optionsDiv_" + xh + "_" + _xxxh + "'>"
            + "<input onkeyup='javascript:insertArry1(this, " + xh + ", " + _xxxh + ");' id='wjnrxxId_" + xh + "' name='wjnrxxName' placeholder='请输入选项' autocomplete='off' class='layui-input'>"
            // + "<a style='cursor:pointer;margin-left:5px' onclick='deleteoptions("+_xxxh+","+xh+")'>增加选项文本</a>"
            + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteoptions(" + _xxxh + "," + xh + ")'>删除</a>"
            + "<div onclick='inputOptions(" + _xxxh + "," + xh + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>"
            + "<a>文本框选项</a>"
            + "</div>"

        $("#options_" + xh + "").after(tmp);
    }

    function deleteOptions(xh) {
        _surveyArr.splice(xh, 1);

        $("#wj_" + xh + "").remove();
        // _xh --;
    }


    function deleteoptions(xxxh, xh) {
        var _surveyOptionsArry = _surveyArr[xh];
        var _optionsArry = _surveyOptionsArry["options"]
        _optionsArry.splice(xxxh, 1);
        $("#optionsDiv_" + xh + "_" + xxxh + "").remove();
    }

    function dateOptions(xh, that) {
        console.log(xh);
        console.log(that);
        var _optionsTitle = _surveyArr[xh].optionsTitle;
        var className = that.className;
        if (className.includes("layui-form-checked")) {
            // 取消选中
            $(that)[0].className = 'layui-unselect layui-form-checkbox'
            var _surveyOptionsArr = _surveyArr[xh];
            var _wjnrxxArry = _surveyOptionsArr['options'];
            _wjnrxxArry[0] = "";

        } else {
            if (CoreUtil.isEmpty(_optionsTitle)) {
                layer.msg("请先填写文本问题内容！");
                return false;
            } else {
                $(that)[0].className = 'layui-unselect layui-form-checkbox layui-form-checked';
            }
            var _surveyOptionsArr = _surveyArr[xh];
            var _wjnrxxArry = _surveyOptionsArr['options'];
            // var xxxhArr = new Array();
            // xxxhArr.push(true);
            _wjnrxxArry[0] = "date";

        }


    }

    function inputOptions(xxxh, xh, that) {
        // layui-unselect layui-form-checkbox layui-form-checked // 选中
        // layui-unselect layui-form-checkbox // 未选中

        var i = _surveyArr[xh].options[xxxh].length;

        var className = that.className;
        if (className.includes("layui-form-checked")) {
            // 取消选中
            $(that)[0].className = 'layui-unselect layui-form-checkbox'

            var _surveyOptionsArr = _surveyArr[xh];
            var _wjnrxxArry = _surveyOptionsArr['options'];
            // var xxxhArr = new Array();
            // xxxhArr.push(false);
            _wjnrxxArry[xxxh][1] = false;

        } else {
            // 选中
            if (i == 0) {
                layer.msg("请先选项填写内容！");
                return false;
            } else {
                $(that)[0].className = 'layui-unselect layui-form-checkbox layui-form-checked'
            }
            var _surveyOptionsArr = _surveyArr[xh];
            var _wjnrxxArry = _surveyOptionsArr['options'];
            // var xxxhArr = new Array();
            // xxxhArr.push(true);
            _wjnrxxArry[xxxh][1] = true;
        }

        console.log(xxxh + "," + xh);

    }


    function insertArry(obj, xh) {
        // console.log("_surveyArrXh："+xh);
        // 在数据组记录
        var _surveyContentArr = _surveyArr[xh];
        _surveyContentArr["optionsTitle"] = obj.value;

    }

    function insertArry1(obj, xh, xxxh) {
        // console.log("_surveyArrXh："+xh + ";xxxh：" + xxxh);
        // 在数据组记录
        var _surveyOptionsArr = _surveyArr[xh];
        var _wjnrxxArry = _surveyOptionsArr['options'];
        var xxxhArr = new Array();
        xxxhArr.push(obj.value);
        _wjnrxxArry[xxxh] = xxxhArr;

    }


</script>

</body>
</html>